package com.jadesoft.stock;


import java.util.Properties;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

public class Mail {
    
    public static void send(String to, String toName, String subject,
            String body) {
        try {
            Properties props = new Properties();
            props.put("mail.smtp.starttls.enable", "true");  
            props.put("mail.smtp.host", "smtp.gmail.com");  
            props.put("mail.smtp.user", "yangzt23@gmail.com");  
            props.put("mail.smtp.password", "yangzhiting");  
            props.put("mail.smtp.port", "587");  //gmail smtp port 587  
            props.put("mail.smtp.auth", "true"); 
            String name = props.getProperty("mail.smtp.user");
            String password = props.getProperty("mail.smtp.password");
            String host = props.getProperty("mail.smtp.host");

            HtmlEmail email = new HtmlEmail();
            // SimpleEmail email = new SimpleEmail();
            email.setHostName(host);// 设置发信的smtp服务器

            email.setAuthentication(name, password);//
            // 如果smtp服务器需要认证的话，在这里设置帐号、密码
            email.setSSL(true);
            email.setSslSmtpPort("465");
            email.setCharset("utf-8");

            email.addTo(to, toName);// 设置收件人帐号和收件人
            email.setFrom("yangzt23@gmail.com", "无名");// 设置发信的邮件帐号和发信人

            email.setSubject(subject);// 设置邮件主题
            email.setHtmlMsg(body);// 设置邮件正文和字符编码

            email.setMsg(body);
            email.send();    
            System.out.println("send succuss");
        } catch (EmailException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
    	long a = System.currentTimeMillis();
        String s = "wlllyx@yahoo.com.cn,wlllyx@yahoo.com.cn,wlllyx@yahoo.com.cn,wlllyx@yahoo.com.cn,wlllyx@yahoo.com.cn";
        String[] name = s.split(",");
//        for (String sr : name) {
        String sr="chunfengxixi@163.com";
//        for(int i=0;i<100;i++){
            new Mail()
                    .send(
                            sr,
                            "无名",
                            "测试eMail",
                            "<html>没事不要乱发邮件给别人！可烦啦！！<img src='http://www.5higo.com/upload/promotion/pic/55da00a929cafad7383fdc5ccba48a0f.png' alt='图片'/>"
                                    + "<b>大厦磊黑涩会</b><html>");
//        }
          System.out.println(System.currentTimeMillis()-a);
    }
}